package cn.qidisoft.edu.hzjt.service.zyc.impl;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.qidisoft.core.common.code.QdfRespCode;
import cn.qidisoft.core.common.exception.dao.DBException;
import cn.qidisoft.core.common.log.LoggerAdapter;
import cn.qidisoft.core.common.log.LoggerAdapterFactory;
import cn.qidisoft.core.common.pagination.Page;
import cn.qidisoft.core.common.pagination.PaginationBean;
import cn.qidisoft.edu.hzjt.dao.zyc.ResearchProjectMapper;
import cn.qidisoft.edu.hzjt.model.zyc.ResearchProject;
import cn.qidisoft.edu.hzjt.model.zyc.ResearchProjectAtt;
import cn.qidisoft.edu.hzjt.model.zyc.ResearchProjectMember;
import cn.qidisoft.edu.hzjt.model.zyc.ResearchProjectStep;
import cn.qidisoft.edu.hzjt.service.zyc.IResearchProjectService;
import cn.qidisoft.edu.hzjt.utils.LogType;

/**
 * 课题管理 提交课题Grid页面 Service 实现层
 * @author zhangwenliang
 *@Date 2018.11.29
 */

@Service
public class ResearchProjectServiceImpl implements IResearchProjectService{
    
	protected static final LoggerAdapter LOGGER = LoggerAdapterFactory.getLogger(LogType.HZJT_LOGGER.val);
	
	
	@Autowired
	private ResearchProjectMapper researchProjectMapper;
	
	@Override
	public PaginationBean<ResearchProject> getListData(Map<String, Object> queryMap, Page page) {
		int c = researchProjectMapper.getCounnt(queryMap);
		int totalRecords = 0;
		totalRecords = (int) c;
		PaginationBean<ResearchProject> pageHolder = new PaginationBean<ResearchProject>(page, totalRecords);
		List<ResearchProject> resultList = researchProjectMapper.getListData(queryMap,
				new RowBounds((pageHolder.getCurrentPage() - 1) * pageHolder.getPageSize(), pageHolder.getPageSize()));
		pageHolder.setPageList(resultList);
		return pageHolder;
	}

	@Override
	public void delete(List<Integer> data) {
		  try {
			  researchProjectMapper.delete(data);
	        } catch (Exception e) {
	            LOGGER.error("delete [{}] error," + this.getClass().getName() + "=[{}]",
	                this.getClass().getName(),
	                ToStringBuilder.reflectionToString(data, ToStringStyle.SHORT_PREFIX_STYLE));
	            throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(),
	                e);
	        }
		
	}

	@Override
	public List<ResearchProject> getResearchProjectList(Map<String, Object> queryMap) {
		return researchProjectMapper.getResearchProjectList(queryMap);
	}

	@Override
	public void insert(ResearchProject researchProject) {
		researchProjectMapper.insert(researchProject);
		
	}

	@Override
	public void insertMember(List<ResearchProjectMember> list) {
		researchProjectMapper.insertMember(list);
	}

	@Override
	public ResearchProjectMember getResearchMember(ResearchProjectMember rMember) {
		
		return researchProjectMapper.getResearchMember(rMember);
	}

	@Override
	public ResearchProject getByKTID(Integer parseInt) {
		
		return researchProjectMapper.getByKTID(parseInt);
	}

	@Override
	public void update(ResearchProject researchProject) {
		researchProjectMapper.update(researchProject);
		
	}

	@Override
	public void deletekTCY(Integer getkTID) {
		researchProjectMapper.deletekTCY(getkTID);
		
	}

	@Override
	public void insertStep(ResearchProjectStep rProjectStep) {
		researchProjectMapper.insertStep(rProjectStep);
		
	}

	@Override
	public List<ResearchProjectStep> getBystepId(ResearchProjectStep researchProjectStep) {
		
		return researchProjectMapper.getBystepId(researchProjectStep);
	}

	@Override
	public void updateStep(ResearchProjectStep rProjectStep) {
		researchProjectMapper.updateStep(rProjectStep);
		
	}

	@Override
	public void batchInserts(List<ResearchProjectAtt> records) {
		
		researchProjectMapper.batchInserts(records);
		
	}

	@Override
	public List<ResearchProjectAtt> queryList(ResearchProjectAtt att) {
		
		return researchProjectMapper.queryList(att);
	}

	@Override
	public int deleteAccessory(ResearchProjectAtt attEntity) {
		
		return researchProjectMapper.deleteAccessory(attEntity);
	}

	@Override
	public ResearchProjectAtt queryByFileId(ResearchProjectAtt attEntity) {
		
		return researchProjectMapper.queryByFileId(attEntity);
	}
	
}
